﻿Imports System.Data.SqlClient
Imports System.Net
Imports System.Security.Principal

Public Class audit


    Private _plantInfo As String
    ''' <summary>
    ''' 替换为当前项目编号
    ''' </summary>
    Public Property plantInfo() As String
        Get
            Return _plantInfo
        End Get
        Set(ByVal value As String)
            _plantInfo = value
        End Set
    End Property

    Private _softwareType As String = "SPP&ID开发"
    ''' <summary>
    ''' 软件（比如spi pid）
    ''' </summary>
    Public Property softwareType() As String
        Get
            Return _softwareType
        End Get
        Set(ByVal value As String)
            _softwareType = value
        End Set
    End Property

    Private _developmentName As String
    ''' <summary>
    ''' 开发项名称（比如pid工具集）
    ''' </summary>
    Public Property developmentName() As String
        Get
            Return _developmentName
        End Get
        Set(ByVal value As String)
            _developmentName = value
        End Set
    End Property
    Private _softwareVersion As String
    ''' <summary>
    ''' 当前版本
    ''' </summary>
    ''' <returns></returns>
    Public Property softwareVersion() As String
        Get
            Return _softwareVersion
        End Get
        Set(ByVal value As String)
            _softwareVersion = value
        End Set
    End Property
    Private _developer As String
    ''' <summary>
    ''' 开发人员
    ''' </summary>
    ''' <returns></returns>
    Public Property developer() As String
        Get
            Return _developer
        End Get
        Set(ByVal value As String)
            _developer = value
        End Set
    End Property

    Private _devCompany As String = "中石化宁波工程有限公司数字技术分公司"
    ''' <summary>
    ''' 公司   中石化宁波工程有限公司数字技术分公司
    ''' </summary>
    ''' <returns></returns>
    Public Property devCompany() As String
        Get
            Return _devCompany
        End Get
        Set(ByVal value As String)
            _devCompany = value
        End Set
    End Property

    Dim sqlconn As String = "Data Source=10.151.129.10;User ID=ZNHDev;Password=ZNHTeam2023;Initial Catalog=DIS;Min Pool Size=20;Max Pool Size=75"


    Public Sub Add()
        Dim windowsIdentify As WindowsIdentity = WindowsIdentity.GetCurrent()
        Dim userName As String = windowsIdentify.Name.Split("\")(1)
        Dim hostName As String = Dns.GetHostName()
        Dim useDate As String = DateTime.Now.ToString()
        Dim sqlstr As String = "INSERT INTO [dbo].[DevelopmentUseInfo]  ([plantInfo],[softwareType],[developmentName],[softwareVersion],[developer],[devCompany],[userName],[hostName],[useDate])  VALUES  ('" + plantInfo + "','" + softwareType + "','" + developmentName + "','" + softwareVersion + "','" + developer + "','" + devCompany + "','" + userName + "','" + hostName + "','" + useDate + "')"

        Dim conn As SqlConnection = New SqlConnection(sqlconn)
        Dim cmd As SqlCommand = New SqlCommand(sqlstr, conn)
        Try

            conn.Open()
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("写入数据审计时，发生错误： " + ex.Message)
        Finally
            conn.Close()
        End Try

    End Sub
    ''' <summary>
    ''' 构造函数
    ''' </summary>
    ''' <param name="plantInfo">当前plant的项目编号</param>
    ''' <param name="developmentName">开发的功能名</param>
    ''' <param name="softwareVersion">版本</param>
    ''' <param name="developer"></param>
    Public Sub New(plantInfo As String, developmentName As String, softwareVersion As String, Optional developer As String = "郁幸恒")
        _plantInfo = plantInfo
        _developmentName = "SPP&ID工具集 - " + developmentName
        _softwareVersion = softwareVersion
        _developer = developer
    End Sub
End Class
